home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / SciAn / src / ScianPostScript.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  8KB  |  298 lines

  1. /*ScianPostScript.c
  2.   Eric Pepke
  3.   June 4, 1993
  4.   PostScript pseudorecorder*/
  5.  
  6. #include "Scian.h"
  7. #include "ScianTypes.h"
  8. #include "ScianArrays.h"
  9. #include "ScianLists.h"
  10. #include "ScianWindows.h"
  11. #include "ScianObjWindows.h"
  12. #include "ScianIcons.h"
  13. #include "ScianControls.h"
  14. #include "ScianButtons.h"
  15. #include "ScianDraw.h"
  16. #include "ScianIDs.h"
  17. #include "ScianPostScript.h"
  18. #include "ScianRecorders.h"
  19. #include "ScianStyle.h"
  20. #include "ScianTemplates.h"
  21. #include "ScianTemplateHelper.h"
  22. #include "ScianTextBoxes.h"
  23.  
  24. static long curFrame = 0;
  25.  
  26. static ObjPtr ReturnTrue(object)
  27. ObjPtr object;
  28. /*Returns true*/
  29. {
  30.     return ObjTrue;
  31. }
  32.  
  33. static ObjPtr PrepareToRecordPostScript(object, nFrames)
  34. ObjPtr object;
  35. long nFrames;
  36. /*Prepares to record nframes*/
  37. {
  38.     curFrame = 0;
  39.     return ObjTrue;
  40. }
  41.  
  42. static ObjPtr SnapOneFramePostScript(object)
  43. ObjPtr object;
  44. /*Snap a single PostScript frame*/
  45. {
  46.     int l, b, r, t,  w, h;
  47.     ObjPtr var;
  48.     char *name;
  49.     ObjPtr windows;
  50.     ThingListPtr runner;
  51.     real scale;
  52.  
  53.     var = GetVar(object, FRAMEOX);
  54.     if (var)
  55.     {
  56.     l = GetInt(var);
  57.     }
  58.     else
  59.     {
  60.     l = 0;
  61.     }
  62.  
  63.     var = GetVar(object, FRAMEOY);
  64.     if (var)
  65.     {
  66.     b = GetInt(var);
  67.     }
  68.     else
  69.     {
  70.     b = 0;
  71.     }
  72.  
  73.     var = GetVar(object, FRAMEWIDTH);
  74.     if (var)
  75.     {
  76.     w = GetInt(var);
  77.     }
  78.     else
  79.     {
  80.     w = 0;
  81.     }
  82.  
  83.     var = GetVar(object, FRAMEHEIGHT);
  84.     if (var)
  85.     {
  86.     h = GetInt(var);
  87.     }
  88.     else
  89.     {
  90.     h = 0;
  91.     }
  92.  
  93.     r = l + w - 1;
  94.     t = b + h - 1;
  95.     if (GetPredicate(object, SAVEWINDOWFRAME))
  96.     {
  97.         l -= WINBL;
  98.         r += WINBR;
  99.         b -= WINBB;
  100.         t += WINBT;
  101.     }
  102.  
  103.     do
  104.     {
  105.     ++curFrame;
  106.     sprintf(tempStr, "screen%04d.eps", curFrame);
  107.     } while (fopen(tempStr, "r"));
  108.  
  109.     SetVar(object, FILENAME, NewString(tempStr));
  110.  
  111.     var = GetVar(object, IMGQUAL);
  112.     if (var)
  113.     {
  114.     imageSubSample = GetInt(var);
  115.     }
  116.     else
  117.     {
  118.     imageSubSample = 0;
  119.     }
  120.  
  121.     var = GetVar(object, ENLARGEMENT);
  122.     if (var)
  123.     {
  124.     scale = GetReal(var) * 0.01;
  125.     }
  126.     else
  127.     {
  128.     scale = 0.5;
  129.     }
  130.  
  131.     drawFile = fopen(tempStr, "w");
  132.     if (drawFile)
  133.     {
  134.     if (GetPredicate(object, SAVEWINDOWFRAME))
  135.     {
  136.         l -= WINFRAMEWID;
  137.         r += WINFRAMEWID;
  138.         b -= WINFRAMEWID;
  139.         t += WINFRAMEWID + WINTITLEHT;
  140.     }
  141.  
  142.     drawingMode = DRAW_POSTSCRIPT;
  143.     BeginDrawing("screen" , l, r, b, t, scale);
  144.  
  145.     windows = GetVar(object, RECORDWINDOWS);
  146.     if (windows)
  147.     {
  148.         runner = LISTOF(windows);
  149.         while(runner)
  150.         {
  151.         WinInfoPtr window;
  152.         int ox, oy;
  153.         int wl, wr, wb, wt;
  154.  
  155.         window = (WinInfoPtr) (runner -> thing);
  156.  
  157.         SelWindow(window);
  158.  
  159.         GetWindowOrigin(&ox, &oy);
  160.         GetWindowBounds(&wl, &wr, &wb, &wt);
  161.  
  162.         SetDrawingWindow(window);
  163.         BeginDrawSubscreen(ox - l, oy - b);
  164.         DrawWindowInfo(window);
  165.         if (GetPredicate(object, SAVEWINDOWFRAME))
  166.         {
  167.             DrawPSFrame(window -> winTitle, ox - l, ox + wr - wl - l, oy - b, oy + wt - wb - b);
  168.         }
  169.         EndDrawSubscreen(ox - l, oy - b);
  170.         RestoreDrawingWindow();
  171.  
  172.         runner = runner -> next;
  173.         }
  174.     }
  175.     EndDrawing(GetPredicate(object, SHOWPAGE));
  176.     drawingMode = DRAW_SCREEN;
  177.     fclose(drawFile);
  178.     }
  179.  
  180.     return ObjTrue;
  181. }
  182.  
  183. static ObjPtr AddPostScriptControls(object, panelContents)
  184. ObjPtr object, panelContents;
  185. /*Adds controls appropriate to a PostScript object to panelContents*/
  186. {
  187.     ObjPtr titleBox, button, radio, var;
  188.     ObjPtr textBox, checkBox;
  189.  
  190.     /*Make title box for quality*/
  191.     titleBox = TemplateTitleBox(PostScriptTemplate, "Image Quality");
  192.     PrefixList(panelContents, titleBox);
  193.     SetVar(titleBox, PARENT, panelContents);
  194.  
  195.     /*Make quality radio button*/
  196.     radio = NewRadioButtonGroup("Quality");
  197.     PrefixList(panelContents, radio);
  198.     SetVar(radio, PARENT, panelContents);
  199.     SetVar(radio, HELPSTRING, NewString("This radio button group sets the quality of \
  200. the image portions of the PostScript file.  Lower numbers give lower quality with a substantial \
  201. savings in file size."));
  202.  
  203.     /*Make the radios*/
  204.     button = TemplateRadioButton(PostScriptTemplate, "Full Quality");
  205.     AddRadioButton(radio, button);
  206.     SetVar(radio, HELPSTRING, NewString("When this radio button is on, the \
  207. image portions of the PostScript file are saved at full quality."));
  208.  
  209.     button = TemplateRadioButton(PostScriptTemplate, "1/2 Quality");
  210.     AddRadioButton(radio, button);
  211.     SetVar(radio, HELPSTRING, NewString("When this radio button is on, the \
  212. image portions of the PostScript file are saved at half quality, resulting in file \
  213. 1/4 as large."));
  214.  
  215.     button = TemplateRadioButton(PostScriptTemplate, "1/3 Quality");
  216.     AddRadioButton(radio, button);
  217.     SetVar(radio, HELPSTRING, NewString("When this radio button is on, the \
  218. image portions of the PostScript file are saved at a third quality, resulting in file \
  219. 1/9 as large."));
  220.  
  221.     button = TemplateRadioButton(PostScriptTemplate, "1/4 Quality");
  222.     AddRadioButton(radio, button);
  223.     SetVar(radio, HELPSTRING, NewString("When this radio button is on, the \
  224. image portions of the PostScript file are saved at a quarter quality, resulting in file \
  225. 1/16 as large."));
  226.  
  227.     AssocDirectControlWithVar(radio, object, IMGQUAL);
  228.  
  229.     /*Make enlarge or reduce*/
  230.     textBox = TemplateTextBox(PostScriptTemplate, "Enlarge or reduce",  ONE_LINE,
  231.         "Enlarge or Reduce");
  232.     PrefixList(panelContents, textBox);
  233.     SetVar(textBox, PARENT, panelContents);
  234.  
  235.     textBox = TemplateTextBox(PostScriptTemplate, "Enlargement",  EDITABLE + WITH_PIT + ONE_LINE,
  236.         "");
  237.     PrefixList(panelContents, textBox);
  238.     SetVar(textBox, PARENT, panelContents);
  239.     AssocTextRealControlWithVar(textBox, object, ENLARGEMENT, 1.0, 1000.0, 0);
  240.     SetVar(textBox, HELPSTRING, NewString("Enter into this text box the amount you would like \
  241. to enlarge or reduce the image on the screen.  100% is full size."));
  242.  
  243.     textBox = TemplateTextBox(PostScriptTemplate, "%", ONE_LINE, "%");
  244.     PrefixList(panelContents, textBox);
  245.     SetVar(textBox, PARENT, panelContents);
  246.  
  247.     checkBox = TemplateCheckBox(PostScriptTemplate,
  248.     "Include 'showpage' at End", 0);
  249.     PrefixList(panelContents, checkBox);
  250.     SetVar(checkBox, PARENT, panelContents);
  251.     AssocDirectControlWithVar(checkBox, object, SHOWPAGE);
  252.     SetVar(checkBox, HELPSTRING, NewString("When this box is checked, a \
  253. 'showpage' will appear at the end of the PostScript file.  This is correct if \
  254. the file will be printed directly.  Otherwise, no 'showpage' will appear.  \
  255. This is correct when using the file as an embedded PostScript file."));
  256.  
  257.     return ObjTrue;
  258. }
  259.  
  260. #ifdef PROTO
  261. void InitPostScript(void)
  262. #else
  263. void InitPostScript()
  264. #endif
  265. /*Create a new PostScript ersatz recorder*/
  266. {
  267.     ObjPtr recorder, icon;
  268.  
  269.     recorder = NewRecorder(NULLOBJ, "PostScript", "Adobe");
  270.     SetMethod(recorder, CONNECT, ReturnTrue);
  271.     SetMethod(recorder, DISCONNECT, ReturnTrue);
  272.     SetMethod(recorder, PREPARETORECORD, PrepareToRecordPostScript);
  273.     SetMethod(recorder, STOPRECORDING, ReturnTrue);
  274.     SetMethod(recorder, SNAPONEFRAME, SnapOneFramePostScript);
  275.     SetVar(recorder, FRAMESOURCE, NewInt(FS_WINDOW));
  276.     SetVar(recorder, ENABLEDSOURCES, NewInt(FB_WINDOW));
  277.     SetVar(recorder, IMGQUAL, NewInt(0));
  278.     SetVar(recorder, SHOWPAGE, ObjTrue);
  279.     SetVar(recorder, ENLARGEMENT, NewReal(50.0));
  280.     AddSnapVar(recorder, IMGQUAL);
  281.     AddSnapVar(recorder, SHOWPAGE);
  282.     AddSnapVar(recorder, ENLARGEMENT);
  283.  
  284.     SetMethod(recorder, ADDCONTROLS, AddPostScriptControls);
  285.     icon = NewIcon(0, 0, ICONRECORDER, "PostScript");
  286.     SetVar(recorder, CONTROLICON, icon);
  287.  
  288.     RegisterRecorder(recorder);
  289. }
  290.  
  291. #ifdef PROTO
  292. void KillPostScript(void)
  293. #else
  294. void KillPostScript()
  295. #endif
  296. {
  297. }
  298.